import React from 'react';

class RecentFive extends React.Component {
    constructor(props) {
        super(props);
        this.displayName = 'RecentFive';
        this.state = {
            // 最近5场比赛的最后两组数据是 平均／总计 行 只有 5个数据
            datas: props.data
        }
    }

    componentWillReceiveProps(nextProps) {
        this.setState({
            datas: nextProps.data
        })
    }

    render() {
        // 显示最近5场比赛数据
        let fiveDataList = this.state.datas.map( function( data, index ) {
            var { date, vs, attack, defense, average } = data;
            return (
                <tr key={index}>
                    <td>{date}</td>
                    <td>{vs}</td>
                    <td>{attack}</td>
                    <td>{defense}</td>
                    <td>{average}</td>
                </tr>
            )
        }.bind(this))
        return (
            <tbody>
                {fiveDataList}
            </tbody>
        );
    }
}

export default RecentFive;
